package grape.composite.service.activity.api;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import grape.common.service.trans.ITransService;
import grape.composite.service.activity.po.Activity;
import grape.common.service.common.IBaseService;

/**
 * <p>
 * 活动表 服务类
 * </p>
 *
 * @author yangwei
 * @since 2020-08-25
 */
public interface IActivityService extends IBaseService<Activity>, ITransService<String,String> {

    public static final String trans_title = "activityTitle";
    public static final String trans_code = "activityCode";
    /**
     * 判断编码是否已存在
     * @param code
     * @return
     */
    default boolean existCode(String code){
        assertParamNotEmpty(code,"code 不能为空");

        Activity activity = new Activity();
        activity.setCode(code);
        int r = count(Wrappers.query(activity));
        return r > 0;
    }

    /**
     * 根据编码查询
     * @param code 不能为空
     * @return
     */
    default Activity getByCode(String code){
        assertParamNotEmpty(code,"code 不能为空");
        Activity activity = new Activity();
        activity.setCode(code);
        return getOne(Wrappers.query(activity));
    }
    @Override
    default boolean support(String type){
        return isEqualAny(type,trans_title, trans_code);
    }

    @Override
    default String trans(String type, String key){
        if (isStrEmpty(key)) {
            return null;
        }
        Activity po = getById(key);
        if (po != null) {
            if (isEqual(type,trans_title)) {
                return po.getTitle();

            }else if (isEqual(type,trans_code)) {
                return po.getCode();
            }
        }
        return null;
    }
}
